import React from "react";

class MyApp extends React.Component {
  state = {
    count: 0,
    // 数据绑定
    sum: ""
  };

  add = () => {
    // this.setState的作用是修改数据和更新ui  数据驱动视图
    this.setState({
      count: this.state.count + 1
    });
  };

  change = e => {
    console.log(e.target.value);
    this.setState({ sum: e.target.value });
  };

  render() {
    return (
      <div>
        我是组件,计数器：{this.state.count}
        <button onClick={this.add}>+</button>
        <input
          type="text"
          value={this.state.sum}
          onChange={this.change}
        ></input>
      </div>
    );
  }
}

export default MyApp;
